/*
 * Copyright 2025 The JA-SIG Collaborative. All rights reserved.
 * distributed with this file and available online at
 */
package com.lap.auth.adapter.driving.query.job.repository;

import com.lap.auth.adapter.driving.query.job.JobQueryConverter;
import com.lap.auth.adapter.driving.query.job.mapper.JobQueryMapper;
import com.lap.auth.adapter.driving.query.job.po.JobQueryPo;
import com.lap.auth.application.job.dto.JobDto;
import com.lap.auth.application.job.dto.QueryJobPageQuery;
import com.lap.auth.application.job.repository.JobQueryRepository;
import com.lap.framework.common.dto.page.PageResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@RequiredArgsConstructor
@Repository
public class JobQueryRepositoryImpl implements JobQueryRepository {

  private final JobQueryConverter jobQueryConverter;
  private final JobQueryMapper jobQueryMapper;

  @Override
  public PageResponse<JobDto> findByConditionPaged(QueryJobPageQuery query) {
    long count = jobQueryMapper.countPageByCondition(query);
    if (count == 0L) {
      return PageResponse.ok(count);
    }
    List<JobQueryPo> list = jobQueryMapper.selectPageByCondition(query);
    return PageResponse.ok(jobQueryConverter.toDtoList(list), count);
  }
}
